"use strict";
const Controller = require("egg").Controller;
// 文件存储
const fs = require("fs");

class DeleteImgController extends Controller {
  async deleteImg() {
    try {
      let imgUrl = this.ctx.request.body.imgUrl;

      fs.unlinkSync("app" + imgUrl);

      this.ctx.body = {
        code: 200,
        imgUrl,
        msg: "删除成功"
      };
    } catch (e) {
      console.log(e);
      this.ctx.body = {
        code: 500,
        msg: "服务器错误"
      };
    }
  }
}

module.exports = DeleteImgController;
